package com.zjsd.sqeybusiness.controller;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import com.zjsd.sqeybusiness.domain.Sjinfo;
import com.zjsd.sqeybusiness.dto.ShareparamDTO;
import com.zjsd.sqeybusiness.service.ISjinfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商机信息Controller
 *
 * @author Zheng
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/sqeybusiness/sjinfo")
public class SjinfoController extends BaseController
{
    @Autowired
    private ISjinfoService sjinfoService;
    @Autowired
    private ISysConfigService sysConfigService;

    /**
     * 查询商机信息列表
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:sjinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sjinfo sjinfo)
    {
        startPage();
        List<Sjinfo> list = sjinfoService.selectSjinfoList(sjinfo);
        return getDataTable(list);
    }

    /**
     * 导出商机信息列表
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:sjinfo:export')")
    @Log(title = "商机信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Sjinfo sjinfo)
    {
        List<Sjinfo> list = sjinfoService.selectSjinfoList(sjinfo);
        ExcelUtil<Sjinfo> util = new ExcelUtil<Sjinfo>(Sjinfo.class);
        return util.exportExcel(list, "sjinfo");
    }

    /**
     * 获取商机信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:sjinfo:query')")
    @GetMapping(value = "/{sjid}")
    public AjaxResult getInfo(@PathVariable("sjid") Long sjid)
    {
        return AjaxResult.success(sjinfoService.selectSjinfoById(sjid));
    }

    /**
     * 新增商机信息
     */
    @Transactional(rollbackFor = Exception.class)
    @PreAuthorize("@ss.hasPermi('sqeybusiness:sjinfo:add')")
    @Log(title = "商机信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sjinfo sjinfo)
    {
        return toAjax(sjinfoService.insertSjinfo(sjinfo));
    }

    /**
     * 修改商机信息
     */
    @Transactional(rollbackFor = Exception.class)
    @PreAuthorize("@ss.hasPermi('sqeybusiness:sjinfo:edit')")
    //@Log(title = "商机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sjinfo sjinfo)
    {
        return toAjax(sjinfoService.updateSjinfo(sjinfo));
    }

    /**
     * 删除商机信息
     */
    @Transactional(rollbackFor = Exception.class)
    @PreAuthorize("@ss.hasPermi('sqeybusiness:sjinfo:remove')")
    //@Log(title = "商机信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sjids}")
    public AjaxResult remove(@PathVariable Long[] sjids)
    {
        return toAjax(sjinfoService.deleteSjinfoByIds(sjids));
    }

    @GetMapping(value = "/getSysConfigByKey")
    public AjaxResult getSysConfigByKey(SysConfig sysConfig)
    {
        String name = sysConfigService.selectConfigByKey(sysConfig.getConfigKey());
        sysConfig.setConfigValue(name);
        return AjaxResult.success(sysConfig);
    }


}
